<template>
  <a-form @submit="handleSubmit" :form="form" class="form">
    <a-row class="form-row">
      <a-col :lg="6" :md="12" :sm="24">
        <a-form-item :label="$t('productName')">
          <a-input
            v-decorator="['info.productName', {rules: [{ required: true, message: $ta('input|productName'), whitespace: true}]}]"
            :placeholder="$ta('input|productName')"
          />
        </a-form-item>
      </a-col>
      <a-col :xl="{span: 6, offset: 2}" :lg="{span: 8}" :md="{span: 12}" :sm="24">
        <a-form-item :label="$t('dataLength')">
          <a-input
            v-decorator="['info.dataLength', {rules: [{ required: true, message: $ta('input|dataLength'), whitespace: true}]}]"
            :placeholder="$ta('input|dataLength')"
          />
        </a-form-item>
      </a-col>
      <a-col :xl="{span: 8, offset: 2}" :lg="{span: 10}" :md="{span: 24}" :sm="24">
        <a-form-item :label="$t('dataBase')">
          <a-select
            :placeholder="$ta('select|dataBase')"
            v-decorator="['info.dataBase', {rules: [{ required: true, message: $ta('input|dataLength'), whitespace: true}]}]"
          >
            <a-select-option
              v-for="item in dataBaseSelectList"
              :value="item.dictValue"
              :key="item.dictLabel"
             >{{ item.dictLabel }}
            </a-select-option>
          </a-select>
        </a-form-item>
      </a-col>
    </a-row>
    <a-row class="form-row">
      <a-col :lg="6" :md="12" :sm="24">
        <a-form-item :label="$t('dataStartFlag')">
          <a-input
            v-decorator="['info.dataStartFlag', {rules: [{ required: false, message: $ta('input|dataStartFlag'), whitespace: true}]}]"
            :placeholder="$ta('input|dataStartFlag')"
          />
        </a-form-item> 
      </a-col>
      <a-col :xl="{span: 6, offset: 2}" :lg="{span: 8}" :md="{span: 12}" :sm="24">
        <a-form-item :label="$t('dataEndFlag')">
          <a-input
            v-decorator="['info.dataEndFlag', {rules: [{ required: false, message: $ta('input|dataEndFlag'), whitespace: true}]}]"
            :placeholder="$ta('input|dataEndFlag')"
          />
        </a-form-item> 
      </a-col>
    </a-row>
    <a-form-item v-if="showSubmit">
      <a-button htmlType="submit" >Submit</a-button>
    </a-form-item>
  </a-form>
</template>

<script>
import { dictPage } from "@/services/dict";
export default {
  name: 'InfoForm',
  props: ['showSubmit'],
  i18n: require('./i18n-productinfo'),
  data() {
    return {
      form: this.$form.createForm(this),
      dataBaseSelectList: []
    }
  },
  mounted() {
    this.initDataBaseSelectList();
  },
  methods: {
    initDataBaseSelectList() {
      dictPage({'entity':{'dictType':'data_base', 'enabled': 1}, 'limit': 0, 'page':0}).then((rep) => {
        this.dataBaseSelectList = rep.data.data.records;
      });
    },
    handleSubmit (e) {
      e.preventDefault()
      this.form.validateFields((err, values) => {
        if (!err) {
          console.log('Received values of form: ', values)
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
  .form{
    .form-row{
      margin: 0 -8px
    }
    .ant-col-md-12,
    .ant-col-sm-24,
    .ant-col-lg-6,
    .ant-col-lg-8,
    .ant-col-lg-10,
    .ant-col-xl-8,
    .ant-col-xl-6{
      padding: 0 8px
    }
  }
</style>
